package com.buybuyyi.stylistcrm.resource.controllers.order;

import com.buybuyyi.stylistcrm.resource.controllers.DefaultController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import stylistcrm.core.query.ResultPagerModel;
import stylistcrm.core.services.order.dto.OrderGoodsDto;
import stylistcrm.core.services.order.dto.QueryOrderConditionDto;
import stylistcrm.core.services.order.dto.TransferOrderDto;
import stylistcrm.core.services.order.enums.EnumExceptionCode;
import stylistcrm.core.services.order.exception.BizException;
import stylistcrm.core.services.order.service.TransferOrderService;

import java.util.List;

/**
 * Created by cheny on 2016/9/6.
 */

@Controller
@RequestMapping("/order")
public class TransferOrderController extends DefaultController{

    @Autowired
    private TransferOrderService transferOrderService;
    @ResponseBody
    @RequestMapping("/createtransferorder")
    public void createTransferOrder(TransferOrderDto transferOrderDto) throws BizException {
        super.checkLogin();
        if(null==transferOrderDto){
            throw new BizException(EnumExceptionCode.EC0001);
        }
        transferOrderService.createTransferOrder(transferOrderDto);
    }
    @ResponseBody
    @RequestMapping("/gettransferorderpagelist")
    public ResultPagerModel<TransferOrderDto> getTransferOrderPageList(QueryOrderConditionDto queryCondition) throws BizException {
        Long userId=super.checkLogin();
        if(null==queryCondition){
            throw new BizException(EnumExceptionCode.EC0001);
        }
        queryCondition.setDesignerId(userId.intValue());
        return transferOrderService.getPageList(queryCondition);
    }
    @ResponseBody
    @RequestMapping("/gettransferorderdetail")
    public TransferOrderDto getTransferOrderDetail(Integer orderId) throws BizException {
        super.checkLogin();
        if(null==orderId){
            throw new BizException(EnumExceptionCode.EC0001);
        }
        return transferOrderService.selectByPrimaryKey(orderId);
    }
    @ResponseBody
    @RequestMapping("/gettransfergoodslist")
    public List<OrderGoodsDto> getTransferGoodsList() throws BizException {
        Long userId=super.checkLogin();
        return transferOrderService.getGoodsList(userId);
    }
}
